<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('创优创标')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<style>
    .bootstrap-tree-table .treetable-tbody td {
        white-space: normal !important;
    }

    .bootstrap-tree-table .treetable-bars .tool-right {
        float: left !important;
        left: 10px;
    }

    .table-striped .table > thead:first-child > tr:first-child > th {
        font-weight: normal;
        font-size: 13px;
        border: 1px solid #cccccc !important;
    }

    .bootstrap-tree-table .treetable-tbody td {
        border: 1px solid #cccccc !important;
        border-top: 0px solid #cccccc !important;
    }

    .select-list li p {
        width: 20px !important;
    }
    .postion{
        display: flex;
        justify-content:space-between;
    }

</style>
<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h3>工程管理中心创优创标计划（总工室）</h3>
                </div>

                <div class="ibox-content">
                    <div class="form-group postion">
                        <a class="btn btn-info" onclick="importExcel('1')">
                            <i class="fa fa-upload"></i> 导入
                        </a>

                        <a class="btn btn-info" onclick="selectOfficeFile('1')">
                            <i class="fa fa-upload"></i> 查看
                        </a>
                    </div>
                </div>
            </div>
        </div>


        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h3>工程管理中心创优创标计划（安全部）</h3>
                </div>
                <div class="ibox-content">
                    <div class="form-group postion">
                        <a class="btn btn-info" onclick="importExcel('2')">
                            <i class="fa fa-upload"></i> 导入
                        </a>

                        <a class="btn btn-info" onclick="selectOfficeFile('2')">
                            <i class="fa fa-upload"></i> 查看
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-suggest-js" />
<th:block th:include="include :: bootstrap-typeahead-js" />

<script th:inline="javascript">

    var prefix = ctx + "excellenceManage";

    var importTemplateUrl = prefix + "/importTemplate";

    var importUrl = prefix + "/importData";

    var title ="";

    // 导入数据
    function importExcel (type) {
        if(type == "1"){
            title = "导入总工室创优创标计划";
        }else{
            title = "导入安全部创优创标计划";
        }

        layer.open({
            type: 1,
            area: ['400px', '230px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: title,
            content: $('#importTpl').html(),
            btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function (index, layero) {
                var file = layero.find('#file').val();
                if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))) {
                    $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                    return false;
                }
                var index = layer.load(2, {shade: false});
                $.modal.disable();
                var formData = new FormData();
                formData.append("file", $('#file')[0].files[0]);
                formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
                $.ajax({
                    url: importUrl+"?type="+type,
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.closeAll();
                            $.modal.alertSuccess(result.msg);
                            $.table.refresh();
                        } else if (result.code == web_status.WARNING) {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertWarning(result.msg)
                        } else {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            }
        });
    }

    // 下载模板
    function importTemplate () {
        $.get(importTemplateUrl, function (result) {
            if (result.code == web_status.SUCCESS) {
                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
            } else if (result.code == web_status.WARNING) {
                $.modal.alertWarning(result.msg)
            } else {
                $.modal.alertError(result.msg);
            }
        });
    }

    // 查看
    function selectOfficeFile(type){
        $.modal.open("总工室创优创标目标清单", prefix + "/selectOfficeFile/"+type);
    }

</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <a onclick="importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>